package com.cn.wanxi.servlet;


import com.cn.wanxi.model.CompanyModel;
import com.cn.wanxi.model.NavModel;
import com.cn.wanxi.model.NewsModel;
import com.cn.wanxi.model.ProductModel;
import com.cn.wanxi.service.*;
import com.cn.wanxi.service.impl.CompanyServiceImpl;
import com.cn.wanxi.service.impl.NavServiceImpl;
import com.cn.wanxi.service.impl.NewsServiceImpl;
import com.cn.wanxi.service.impl.ProductServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/home")
public class HomeServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        ICompanyService iCompanyService=new CompanyServiceImpl();
        CompanyModel  companyModel=iCompanyService.getCompanyModel();
        req.setAttribute("companyModel", companyModel);//key唯一的，命名见名知意  value


        INavService iNavService=new NavServiceImpl();
        List<NavModel> navList = iNavService.getNavList();
        req.setAttribute("navList", navList);


//        NewsService newsService = new NewsService();
//        List<NewsModel> newsModelList = newsService.getNewsModelListForHomeFromIO();
        INewsService iNewsService=new NewsServiceImpl();
        List<NewsModel> newsModelList=iNewsService.getList();
        req.setAttribute("newsList", newsModelList);


//        ProductService productService = new ProductService();
//        List<ProductModel> productModelList = productService.getProductListForHomeFromIO();
        IproductService iproductService=new ProductServiceImpl();
        List<ProductModel> productModelList=iproductService.getList();
        req.setAttribute("productList", productModelList);

        req.getRequestDispatcher("/jsp/home.jsp").forward(req, resp);
//        resp.sendRedirect("/jsp/home.jsp");//只跳转页面
//        doget和dopost的区别
//        转发和重定向的区别
    }

//    doget  安全性 低    传值大小  小  1  1.5kb
//    dopost   高   多  理论上  不限制

//    查询都用get  其他 增加修改删除 都用post
}
